package com.stars.empoly.utils

import android.app.Activity
import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import coil.load
import com.qmuiteam.qmui.kotlin.onClick
import com.qmuiteam.qmui.layout.QMUIFrameLayout
import com.qmuiteam.qmui.skin.QMUISkinValueBuilder
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.widget.popup.QMUIPopup
import com.qmuiteam.qmui.widget.popup.QMUIPopups
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundLinearLayout
import com.stars.empoly.R
import com.stars.empoly.inte.ChoiceData

/**
 *上传车辆交付图片
 *on 2020/9/21
 */
object  PopuImgUtils {



    var  img:ImageView?=null
    var path:String?=""

    fun show(activity:Activity, view: View, choiceData: ChoiceData ){

        var mNormalPopup = QMUIPopups.fullScreenPopup(activity)
        val builder: QMUISkinValueBuilder = QMUISkinValueBuilder.acquire()
        val frameLayout = QMUIFrameLayout(activity)
        //自定义布局
        val layoutInflater = activity?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        var layout = layoutInflater.inflate(R.layout.popu_img, null)

        val llChoseImg:QMUIRoundLinearLayout=layout.findViewById(R.id.ll_chose_img)
        val llChoseImgTo: QMUIRoundLinearLayout =layout.findViewById(R.id.ll_chose_img_to)
         img=layout.findViewById(R.id.img)


        val tvCancel:TextView=layout.findViewById(R.id.tv_cancel)
        val tvSure:TextView=layout.findViewById(R.id.tv_sure)

        llChoseImg.onClick {
           //选择照片
            ChosePhotoUtils.getChosePhoto(activity, 1)

        }
        llChoseImgTo.onClick {
            //选择照片
            ChosePhotoUtils.getChosePhoto(activity, 1)

        }



        tvCancel.onClick {
            mNormalPopup.dismiss()
        }

        tvSure.onClick {

            if(TextUtils.isEmpty(path)){

                Toast.makeText(activity, "请上传标志性的交车照片", Toast.LENGTH_SHORT).show()
                return@onClick
            }
            choiceData?.onRestuse("")

            mNormalPopup.dismiss()
        }


        builder.release()

        val size= QMUIDisplayHelper.getScreenWidth(activity)


        val lp: FrameLayout.LayoutParams = FrameLayout.LayoutParams(size,
                FrameLayout.LayoutParams.WRAP_CONTENT)
        frameLayout.addView(layout, lp)

        mNormalPopup.addView(frameLayout)
        mNormalPopup.onDismiss() {
        }

        mNormalPopup.dismissIfOutsideTouch(false)
        mNormalPopup.animStyle(QMUIPopup.ANIM_GROW_FROM_CENTER)
        mNormalPopup.show(view)


    }


    fun setImg(url:String?){
        path=url
        img?.load(url)

    }




}
